package com.tpyule.tpclass.service.impl;

import com.tpyule.tpclass.dao.SectionDao;
import com.tpyule.tpclass.entity.bo.SectionStudyBo;
import com.tpyule.tpclass.entity.pojo.Section;
import com.tpyule.tpclass.service.SectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @author zzz
 * @version 1.0
 * @date 2020/3/29 20:58
 */
@Service
public class SectionServiceImpl implements SectionService {
    @Autowired
    SectionDao sectionDao;
    @Override
    public List<Section> getListSectionByChapterId(String chapterId) {
        return sectionDao.getListSectionByChapterId(chapterId);
    }

    @Override
    public String updateSection(Section section) {
        int result =  sectionDao.updateSection(section);
        if (section.getRemove() == 0) {
            sectionDao.updateBigSection(section);
        }
        if(result != -1) {
            return "success";
        } else {
            return "error";
        }
    }

    @Override
    public int updateBigSection(Section section) {
        return sectionDao.updateBigSection(section);
    }

    @Override
    public Section addSection(Section section) {
        section.setSectionId(UUID.randomUUID().toString().toUpperCase());
        int result = sectionDao.addSection(section);
        if (result != -1) {
            return section;
        } else {
            return null;
        }
    }

    @Override
    public int getSectionSize(String courseId) {
        if(courseId!=null){
            return sectionDao.getSectionSize(courseId);
        }else {
            return -1;
        }
    }

    @Override
    public List<SectionStudyBo> getSectionStudy(String chapterId, String userId) {
        return sectionDao.getSectionStudy(chapterId,userId);
    }

    @Override
    public Section getSection(String sectionId) {
        return sectionDao.getSection(sectionId);
    }

    @Override
    public Section getIndexSection(String courseId) {
        return sectionDao.getIndexSection(courseId);
    }
}
